#!/bin/bash
#功能函数
funcs=`which functions.sh`
if [ "$funcs" != "" ] ;then
    . $funcs
else
    funcs=`dirname $0`/functions.sh
    echo "$PWD"
    echo "funcs=$funcs"
    if [ "$funcs" != "" ] ;then
	. $funcs
    else
	exit
    fi
fi


#脚步入口：解析参数
while test $# != 0
do
    case $1 in
	-t)
	    shift
	    type=$1
	    ;;
	-m)
	    shift
	    mode=$1
	    ;;
	-d)
	    shift
	    search_dir=$1
	    ;;
	-name)
	    shift
	    name=$1
	    ;;

        *)
	    name=$1
	    ;;
       esac
       shift
done
if [ "$mode" == "auto" ]; then
    suffixs=$suffixs
fi



if [ -n "$name" ]; then
    ac_grep="grep $name"
else
    ac_grep=
fi


if [ -n "$suffixs" ]; then
    for suffix in $suffixs
    do
    if [ "$suffix" = "*" ]; then
       suffix=""
    fi
    if [ "$type" = "text" ] || [ "$type" = "t" ]; then
        echo "suffix=$suffix"
        echo "search_di=$search_dir"
	aaa=`find  $search_dir -path '*/.*'   -prune -o -type f -name "*$suffix" -print |perl -e 'while(<>){s/\n//;if(-T){print $_."\n"}}'`
        if [ -n "$name" ]; then aaa=`find  $search_dir -path '*/.*'  -prune -o -type f  -name "*$suffix" -print |perl -e 'while(<>){s/\n//;if(-T){print $_."\n"}}'`; fi
    else
	aaa=`find  $search_dir -path '*/.*'  -type f  -prune -o -name "*$suffix" -print`
        if [ -n "$name" ]; then aaa=`find  $search_dir -path '*/.*'  -prune -o -type f  -name "*$suffix" -print`; fi
    fi
    aaa="$aaa" 
    done
else
    if [ "$type" = "text" ] || [ "$type" = "t" ]; then
 	aaa=`find  $search_dir -path '*/.*'  -type f  -prune -o  -print |perl -e 'while(<>){s/\n//;if(-T){print $_."\n"}}'`
        if [ -n "$name" ]; then aaa=`find  $search_dir -path '*/.*'  -prune -o -type f   -name "*$suffix" -print |perl -e 'while(<>){s/\n//;if(-T){print $_."\n"}}'`; fi    else
	aaa=`find  $search_dir -path '*/.*'   -prune -o  -type f -name "*$suffix" -print`
        if [ -n "$name" ]; then aaa=`find  $search_dir -path '*/.*'  -prune -o -type f  -print`; fi
    fi
fi
echo "$aaa"
exit
